﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NFit.Core.Interfaces;
using System.IO;

namespace NFit.Core.BaseClasses
{
    /// <summary>
    /// Base class for report writer
    /// </summary>
    public abstract class BaseReportWriter : IReportWriter
    {
        /// <summary>
        /// The custom writer for the fixtures
        /// </summary>
        public virtual ISpecificationWriter Writer { get; set; }

        /// <summary>
        /// Make the report for the associated summary
        /// </summary>
        /// <param name="summary"></param>
        public virtual void Report(ExecutionSummary summary)
        {
            WriteSpecs(summary.RunnedSpecs);
        }

        /// <summary>
        /// Get the output stream
        /// </summary>
        /// <returns></returns>
        protected abstract Stream GetReportStream();

        /// <summary>
        /// Write a list of specs
        /// </summary>
        /// <param name="specs"></param>
        protected void WriteSpecs(IEnumerable<SpecificationDefinition> specs)
        {
            if (specs != null)
            {
                foreach (var spec in specs)
                {
                    WriteSpec(spec);
                }
            }
        }

        /// <summary>
        /// Write the given specification and all its childs
        /// </summary>
        /// <param name="spec"></param>
        public abstract void WriteSpec(SpecificationDefinition spec);
    }
}
